package com.act.utils.vueMenu;

/**
 * @author: mengxiangzhong
 * @date: 2023/2/7 9:21
 * @TODO:
 **/



import java.io.Serializable;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.act.moudles.user.entity.Menu;
import com.fasterxml.jackson.annotation.JsonInclude;


public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    private Boolean hasChecked = false;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public <T> TreeSelect(T t) {
    }


    public TreeSelect(Menu menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        this.hasChecked = menu.getHasChecked();
    }

    public  <T>TreeSelect (T t , Function<T,Long> idFuc,Function<T,String> nameFunc,
                          Function<T,List<T>> childFunc,Function<T,Boolean> checkFunc){
        this.id = idFuc.apply(t);
        this.label = nameFunc.apply(t);
        this.children = childFunc.apply(t).stream().map(TreeSelect::new).collect(Collectors.toList());
        this.hasChecked = checkFunc.apply(t);
//        return this;
    }



    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public List<TreeSelect> getChildren() {
        return children;
    }

    public void setChildren(List<TreeSelect> children) {
        this.children = children;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Boolean getHasChecked() {
        return hasChecked;
    }

    public void setHasChecked(Boolean hasChecked) {
        this.hasChecked = hasChecked;
    }

    public  void  buildTree(Menu menu){

    }
}

